package com.test.socket;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Logger;

public class TCPEchoServerThread {

	public static void main(String  args)throws IOException{
		int echoServPort =Integer.parseInt("8086");//server port
		
		//create a server socket to accept client connection requests
		ServerSocket servSock = new ServerSocket(echoServPort);
		
		Logger logger = Logger.getLogger("practical");
		//run forever , accepting and spawning a thread for each connection
		while(true){
			Socket clntSock = servSock.accept();//block waiting for connection
			//spawn thread to handle new connection 
			Thread  thread = new Thread(new EchoProtocol(clntSock, logger));
			thread.start();
			logger.info("Created and started Thread "+thread.getName());
			
		}
	}
}
